package com.jack.vipmis.vip.wei.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.jack.vipmis.common.entity.search.SearchOperator;
import com.jack.vipmis.common.entity.search.Searchable;
import com.jack.vipmis.common.service.BaseService;
import com.jack.vipmis.vip.wei.entity.WeiEntity;
import com.jack.vipmis.vip.wei.repository.WeiEntityRepository;

/**
 * 微贴Service
 * 
 * @author JackLiang
 * @version 1.0
 * @date 2014-8-27
 */
@Service
public class WeiEntityService extends BaseService<WeiEntity, Long> {

	private static final int	pageSize	= 10;

	private WeiEntityRepository getWeiEntityRepository() {
		return (WeiEntityRepository) baseRepository;
	}

	/**
	 * 分页查询
	 * 
	 * @param page
	 * @param text
	 *            检索内容
	 * @return
	 */
	public Page<WeiEntity> list(int page, String text) {
		Searchable searchable = Searchable.newSearchable();
		searchable.addSearchFilter("title", SearchOperator.like, text);

		searchable.setPage((page - 1), pageSize);
		searchable.addSort(Direction.DESC, "createTime");

		return getWeiEntityRepository().findAll(searchable);
	}
}
